<template>
  <div>
      <common-head title="立即购买"/>
      <div class="wrap">
        <!-- 联系人 -->
        <van-contact-card
          :type="contactType"
          :name="orderContact.name"
          :tel="orderContact.tel"
          @click="onEdit"
        />
        <!-- /联系人 -->
        <!-- 商品 -->
        <div class="items">
          <div class="item" v-for="item in currentOrder.items" :key="item.id">
            <van-card
              :num="item.num"
              :price="item.minPrice"
              :title="item.name"
              :thumb="item.pic"
            />
          </div>
        </div>
        <!-- /商品 -->
      </div>
      <van-submit-bar :price="currentOrder.total*100" button-text="支付" @submit="onSubmit" />
  </div>
</template>

<script>
import CommonHead from '@components/CommonHead'
import { mapState } from 'vuex'
export default {
  methods: {
    onEdit () {
      if (this.contactType === 'edit') {
        // 点击选择另一个联系人
        this.$router.push('/contactLists')
      } else {
        // 增加联系人
      }
    },
    onSubmit () {
      alert('恭喜购买成功，等待收货吧')
    }
  },
  components: {
    CommonHead
  },
  computed: {
    ...mapState({
      currentOrder: state => state.order.currentOrder,
      orderContact: state => state.order.orderContact
    }),
    contactType () {
      return this.orderContact ? 'edit' : 'add'
    }
  }
}
</script>

<style lang="scss" scoped>
.wrap{
  padding-top: 46px;
  padding-bottom: 50px;
}
</style>
